import os
import glob
import pytest


def run():
    test_files = glob.glob('./case_script/testcase*.py')
    if not test_files:
        raise FileNotFoundError("未找到测试文件，请检查路径或命名规则！")
    # 生成原始测试数据
    pytest.main(['-v', *test_files, '--alluredir', './report/allure-results', '--clean-alluredir'])
    # 生成持久化HTML报告
    os.system('allure generate ./report/allure-results -o ./report/allure-report --clean')
    # 自动打开报告
    os.system('allure open ./report/allure-report')


if __name__ == '__main__':
    run()